unit oFPedestrian;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, oProcessItem, oProcessObjects,oProcessObjectConstants,
  oManager;

type
  TfPedestrian = class(TFrame)
    btnSave: TButton;
    btnCancel: TButton;
    lName: TLabel;
    lCrowdTightning: TLabel;
    lDiameter: TLabel;
    lAvgVelocity: TLabel;
    lMaxVelocity: TLabel;
    lMaxAcceleration: TLabel;
    lView: TLabel;
    eName: TEdit;
    eCrowdTightning: TEdit;
    eDiameter: TEdit;
    eAvgVelocity: TEdit;
    eMaxVelocity: TEdit;
    eMaxAcceleration: TEdit;
    eView: TEdit;
    procedure btnSaveClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    function getPedestrian : TPedestrianData;
  private
    aMaster : TManager;
    aEditing : boolean;
    { Private declarations }
  public
    { Public declarations }
    constructor Create(paMaster : TManager);
    property Editing : boolean read aEditing write aEditing;
  end;

implementation
uses oPedestrianEditorManager;
{$R *.dfm}

procedure TfPedestrian.btnCancelClick(Sender: TObject);
begin
  Visible := false;
end;

procedure TfPedestrian.btnSaveClick(Sender: TObject);
begin
  if Editing then
      aMaster.ProcessObject(TProcessItem.create(PO_PEDMAN_EDIT,
                                    getPedestrian))
  else
      aMaster.ProcessObject(TProcessItem.create(PO_PEDMAN_INSERT,
                                    getPedestrian));
  Editing := not Editing;
end;

constructor TfPedestrian.Create(paMaster: TManager);
begin
  aMaster := paMaster;
end;

function TfPedestrian.getPedestrian: TPedestrianData;
var
  data : TPedestrianData;
begin
  data := TPedestrianData.Create('', 0);
  try
      data.NameData := eName.Text;
      data.CrowdTightningData := StrToFloat(eCrowdTightning.Text);
      data.DiameterData := StrToFloat(eDiameter.Text);
      data.AvgVelocityData := StrToFloat(eAvgVelocity.Text);
      data.MaxVelocityData := StrToFloat(eMaxVelocity.Text);
      data.MaxAccelerationData := StrToFloat(eMaxAcceleration.Text);
      data.ViewData := StrToFloat(eView.Text);
      Result := data;
  except
    on e : Exception do raise EPedestrianEditorManager.Create('Error on getting data');
    on pe : EPedestrianEditorManager do
     begin
       data.Free;
       Result := nil;
     end;
  end;
end;


end.
